package com.csmy.form;

import java.awt.EventQueue;

import javax.swing.JFrame;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import java.awt.FlowLayout;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JToggleButton;
import javax.swing.KeyStroke;
import java.awt.event.KeyEvent;
import java.awt.event.InputEvent;
import java.awt.event.WindowEvent;

import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;
import javax.swing.SwingConstants;


public class Form {

	private JFrame frame;
	private JPanel content;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Form window = new Form();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Form() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setExtendedState(JFrame.MAXIMIZED_BOTH);   //�������
		frame.setUndecorated(true); //ȥ��Jframe�ж�window��װ��
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(new BorderLayout(0, 0));
		
		JPanel header = new JPanel();
		header.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
		frame.getContentPane().add(header, BorderLayout.NORTH);
		header.setLayout(new BorderLayout(0, 0));
		
		JMenuBar menuBar = new JMenuBar();
		menuBar.setBackground(Color.WHITE);
		menuBar.setForeground(Color.GREEN);
		header.add(menuBar, BorderLayout.CENTER);
		
		JMenu bookMeun = new JMenu("\u56FE\u4E66\u7BA1\u7406");
		menuBar.add(bookMeun);
		
		JMenuItem bookSelect = new JMenuItem("\u67E5\u8BE2\u56FE\u4E66");
		bookSelect.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SelectForm selectform;
				try {
					selectform = new SelectForm();
					selectform.setVisible(true);
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		bookSelect.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK));
		bookMeun.add(bookSelect);
		//����ͼ��
		JMenuItem bookAdd = new JMenuItem("\u589E\u52A0\u56FE\u4E66");
		bookAdd.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				InsertForm frame = new InsertForm();
				frame.setVisible(true);
			}
		});
		bookAdd.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK));
		bookMeun.add(bookAdd);
		//ͼ���޸�
		JMenuItem bookAlter = new JMenuItem("\u4FEE\u6539\u56FE\u4E66");
		bookAlter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				UpdateForm frame = new UpdateForm();
				frame.setVisible(true);
				frame.setLocationRelativeTo(null);
				
			}
		});
		bookAlter.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
		bookMeun.add(bookAlter);
		
		JMenuItem bookDelete = new JMenuItem("\u5220\u9664\u56FE\u4E66");
		bookDelete.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DelectForm frame = new DelectForm();
				frame.setVisible(true);
			}
		});
		bookDelete.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK));
		bookMeun.add(bookDelete);
		
		
		//ͼ��¼��
		JMenu menu = new JMenu("\u8BFB\u8005\u7BA1\u7406");
		menuBar.add(menu);
		
		
		//��ʼ¼��
		JMenuItem menuItem = new JMenuItem("\u8BFB\u8005\u5F55\u5165");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ReaderForm readerframe = new ReaderForm();
				readerframe.setVisible(true);
				
			}
		});
		menu.add(menuItem);
		
		JButton button = new JButton("\u9000\u51FA");
		//button.setIcon(new ImageIcon("D:\\\u7528\u6237\u76EE\u5F55\\\u6211\u7684\u56FE\u7247\\0008020221769995_b.jpg"));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				frame.dispatchEvent(new WindowEvent(frame,WindowEvent.WINDOW_CLOSING) );
			}
		});
		button.setHorizontalAlignment(SwingConstants.RIGHT);
		menuBar.add(button);
		
		
		JPanel state = new JPanel();
		state.setBackground(Color.LIGHT_GRAY);
		state.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		FlowLayout fl_state = (FlowLayout) state.getLayout();
		fl_state.setAlignment(FlowLayout.LEFT);
		frame.getContentPane().add(state, BorderLayout.SOUTH);
		
		JLabel lblNewLabel = new JLabel("\u63D0\u793A\u4FE1\u606F");
		state.add(lblNewLabel);
		
		content = new JPanel();
		frame.getContentPane().add(content, BorderLayout.CENTER);
		content.setLayout(new BorderLayout(0, 0));
		
		JToolBar toolBar = new JToolBar();
		toolBar.setBackground(Color.LIGHT_GRAY);
		content.add(toolBar, BorderLayout.NORTH);
		
		JButton btnNewButton = new JButton("");
		btnNewButton.setIcon(new ImageIcon(Form.class.getResource("/javax/swing/plaf/basic/icons/JavaCup16.png")));
		toolBar.add(btnNewButton);
		
		JToggleButton tglbtnNewToggleButton = new JToggleButton("");
		tglbtnNewToggleButton.setForeground(Color.BLACK);
		//tglbtnNewToggleButton.setIcon(new ImageIcon(Form.class.getResource("/com/sun/java/swing/plaf/motif/icons/ScrollDownArrow.gif")));
		tglbtnNewToggleButton.setToolTipText("\u8FD9\u662F\u6D4B\u8BD5");
		toolBar.add(tglbtnNewToggleButton);
		
		JButton btnNewButton_1 = new JButton("");
		//btnNewButton_1.setIcon(new ImageIcon("H:\\Myeclipse\\BookSys\\src\\img\\105-160H1113303164.jpg"));
		btnNewButton_1.setForeground(Color.BLUE);
		btnNewButton_1.setFont(new Font("΢���ź�", Font.PLAIN, 60));
		btnNewButton_1.setBackground(Color.CYAN);
		btnNewButton_1.setText("ͼ�����ϵͳ");
		content.add(btnNewButton_1, BorderLayout.CENTER);
	}

	protected DelectForm delectForm() {
		// TODO Auto-generated method stub
		return null;
	}

}
